// OGoMojo
// Whitemice.MOGI.ZOGI.Document
// License: LGPL
// Copyright: Whitemice Consulting, 2006
// Author(s): Adam Tauno Williams (awilliam@whitemice.org)
using System;
using Whitemice.MOGI;

namespace Whitemice.MOGI.ZOGI
{	
	public abstract class Document : Whitemice.MOGI.Document, IDocument 
	{
		protected Payload	payload;
		
		public Document(IServer server, Payload payload) : base(server)
		{
			this.payload = payload;
		}
		
		internal Payload Payload
		{
			get { return payload; }
			set { payload = value; }
		}
		
		public override string Name
		{
			get
			{
				Console.WriteLine("MOGI.ZOGI.Document.Name_get");
				return "Document/" +
								payload.GetStringForKey("entityName") + "/" +
								payload.GetIntForKey("objectId").ToString();
			}
		}
		
		public virtual string Number
		{
			get { return "OGo" + Name.Split('/')[2]; }
			set { }
		}
		
		public bool HasExtendedAttribute(string attribute)
		{
			return payload.HasCompanyValue(attribute);
		}
		
		public void ExtendedAttribute(string attribute, object value)
		{
		}
		
		public object ExtendedAttribute(string attribute)
		{
			if(HasExtendedAttribute(attribute))
				return payload.GetPayloadForKey("_COMPANYVALUES").GetObjectForKey(attribute);
			return null;
		}		
		
		public bool IsModified
		{
			get { return true; }
		}
		
		public int Version
		{
			get { return payload.GetIntForKey("version"); }
		}	
	}
}
